<link rel="stylesheet" href="<?php echo STATIC_URL.'/backend/css/notice.css'?>" />

<script>
function closeFancy(){
    parent.jQuery.fancybox.close();
}
function sending(){
    $("#success").html("<img src='<?php echo STATIC_URL;?>/backend/images/icon/loading-2.gif' /> <br/> Vui lòng chờ");
    $("#sendSMS").attr('disabled','disabled');
    $("#cancelSMS").attr('disabled','disabled');
    setTimeout(function () {
        $.ajax(
            {
                url : '/auth/telecom/sendsms',
                type: "POST",
                data : { phone: $("#p_phone").val().trim(), message:$("#message").val().trim()},
                cache: true,
                beforeSend: function(){
                    $("#success").html("<img src='<?php echo STATIC_URL;?>/backend/images/icon/loading-2.gif' /> <br/> Đang xử lí");
                    $("#sendSMS").attr('disabled','disabled');
                    $("#cancelSMS").attr('disabled','disabled');
                },
                success:function(data)
                {
                    setTimeout(function () {
                        if(data==0){
                            $("#success").html("Gởi tin nhắn thành công!");
                            $("#sendSMS").attr('disabled','disabled');
                            $("#cancelSMS").attr('disabled','disabled');
                            setTimeout(function () {
                                closeFancy();
                            },2000);
                            
                        } else {
                            $("#sendSMS").removeAttr('disabled');
                            $("#cancelSMS").removeAttr('disabled');
                            $("#success").html("Gởi tin nhắn thất bại!");
                        }
                    },2000);
                },
                error: function() 
                {
                    $("#success").html("Gởi tin nhắn thất bại!");
                }
            });
     },2000);
    
    
}
</script>

<div id="container2">
    <h3 id="nav2" class="logo">
        <a id="logo">GỞI TIN NHẮN</a>
    </h3>
    <div id="wufoo-mz9i3ib0wkzqls">
        <ul>
            <li>
                <?php
                    //ho ten
                    echo form_label($this->lang->line('phone'), 'phone');
                    echo form_input(array('name' => 'p_phone', 'id' => 'p_phone', 'value' => $phone,'required'=>'required','placeholder'=>$this->lang->line('phone')));
                    echo form_error('phone');

                     //Ghi chú
                    $info           =   $this->telecom_model->getOwnerFromTblUser($this->session->userdata['user_id']);
                    $lastname       =   $info[0]->lastname;
                    $phone          =   ($info[0]->phone)?'-'.$info[0]->phone.'-':'-';
                    echo form_label($this->lang->line('message'), 'message');
                    echo form_textarea(array('name' => 'message', 'id' => 'message', 'value' => $this->lang->line('prefixMsg').$lastname.$phone.$this->lang->line('behindfixMsg'),'required'=>'required','rows'=>'10','maxlength'=>'160','placeholder'=>$this->lang->line('limit160')));
                    echo form_error('message');
                 ?>
            </li>
        </ul>
        <div class="top-button">
                <?php echo form_button(array('id' => 'sendSMS', 'name' => 'submit', 'content' => $this->lang->line('send'),'class' => 'btn btn-primary','onclick'=>'sending()')); ?>
                <?php echo form_button(array('id' => 'cancelSMS','content' => $this->lang->line('close'),'class' => 'btn','onclick'=>'closeFancy()')); ?>
        </div>
        <div id="success"></div>
    </div>
</div>
